<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2_批量传递props属性</title>
</head>

<body>
    <div id="app"></div>
    <div id="app2"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script type="text/babel">
        class MyComponent extends React.Component{
            render(){
                const {name,age} = this.props.userInfo
                return (
                    <div>
                        <ul>
                            <li>姓名：{name}</li>
                            <li>年龄：{age}</li>    
                        </ul>    
                    </div>
                )
            }
        }
        const userInfo = {
            name:"李四",
            age:18
        }
        // props可以直接传递一个对象
        ReactDOM.render(<MyComponent userInfo={userInfo}/>,document.getElementById("app"))

        // 在React中给我们提供了一个新的语法，使用{...}的方式批量传递props信息，需要注意的是，这种方法在解构取值时，
        // 必须要和传递过去的属性值一致，同时这种写法也是上面写法的语法糖
        ReactDOM.render(<MyComponent {...userInfo}/>,document.getElementById("app2"))
    </script>
</body>

</html>